import * as VueRouter from 'vue-router'
import Nprogress from 'nprogress'

const defalutRoutes = [
    // {
    //   path: '/',
    //   redirect: '/login'
    // },
    // {
    //   path: '/login',
    //   name: 'Login',
    //   component: () => import('@/views/login/index.vue'),
    // },
  ]

class AppRouterManger {
    router
    constructor(){
        this.router = VueRouter.createRouter({
            history: VueRouter.createWebHashHistory(),
            routes: defalutRoutes
        })
        this.initRouter()
    }

    initRouter() {
        this.router.beforeEach(async(to, from, next) => {
            Nprogress.start()
            next()
        })
        this.router.afterEach(() => {
            // 路由加载完成后关闭进度条
            Nprogress.done()
        })
          
        this.router.onError(() => {
            // 路由发生错误后销毁进度条
            Nprogress.remove()
        })
    }
}

const appRouterManger = new AppRouterManger()   

export default appRouterManger